﻿using System;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Maticsoft.DBUtility;
using System.Collections.Generic;

namespace ElingOA6_Admin_DSJCJ.DAL
{
    /// <summary>
    /// LinkTypeEntry数据类
    /// </summary>
    public class LinkTypeEntry
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public LinkTypeEntry()
        { }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-15</date>
        /// <param name="strWhere">查询条件</param>
        /// <returns>DataSet表</returns>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FLinkTypeEntryID,FLinkText,FDispSeq,FLinkURL,FOldFileName,FNewFileName,FExtName,FFileContent,FLinkTypeCD,FEntityNo ");
            strSql.Append(" FROM t_LinkTypeEntry ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-15</date>
        /// <param name="model">model对象</param>
        public void Add(Model.LinkTypeEntry model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into t_LinkTypeEntry(");
            strSql.Append("FLinkText,FDispSeq,FLinkURL,FOldFileName,FNewFileName,FExtName,FFileContent,FLinkTypeCD,FEntityNo)");
            strSql.Append(" values (");
            strSql.Append("@FLinkText,@FDispSeq,@FLinkURL,@FOldFileName,@FNewFileName,@FExtName,@FFileContent,@FLinkTypeCD,@FEntityNo)");
            SqlParameter[] parameters = {
					new SqlParameter("@FLinkText", SqlDbType.NVarChar,40),
					new SqlParameter("@FDispSeq", SqlDbType.Int,4),
					new SqlParameter("@FLinkURL", SqlDbType.NVarChar,255),
					new SqlParameter("@FOldFileName", SqlDbType.NVarChar,255),
					new SqlParameter("@FNewFileName", SqlDbType.NVarChar,255),
					new SqlParameter("@FExtName", SqlDbType.NVarChar,80),
					new SqlParameter("@FFileContent", SqlDbType.Image),
					new SqlParameter("@FLinkTypeCD", SqlDbType.NVarChar,6),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)};
            parameters[0].Value = model.FLinkText;
            parameters[1].Value = model.FDispSeq;
            parameters[2].Value = model.FLinkURL;
            parameters[3].Value = model.FOldFileName;
            parameters[4].Value = model.FNewFileName;
            parameters[5].Value = model.FExtName;
            parameters[6].Value = model.FFileContent;
            parameters[7].Value = model.FLinkTypeCD;
            parameters[8].Value = model.FEntityNo;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-15</date>
        /// <param name="model">model对象</param>
        public void Update(Model.LinkTypeEntry model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update t_LinkTypeEntry set ");
            strSql.Append("FLinkText=@FLinkText,");
            strSql.Append("FDispSeq=@FDispSeq,");
            strSql.Append("FLinkURL=@FLinkURL,");
            strSql.Append("FOldFileName=@FOldFileName,");
            strSql.Append("FNewFileName=@FNewFileName,");
            strSql.Append("FExtName=@FExtName,");
            strSql.Append("FFileContent=@FFileContent");
            strSql.Append(" where FLinkTypeEntryID=@FLinkTypeEntryID and FLinkTypeCD=@FLinkTypeCD and FEntityNo=@FEntityNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FLinkTypeEntryID", SqlDbType.Int,4),
					new SqlParameter("@FLinkText", SqlDbType.NVarChar,40),
					new SqlParameter("@FDispSeq", SqlDbType.Int,4),
					new SqlParameter("@FLinkURL", SqlDbType.NVarChar,255),
					new SqlParameter("@FOldFileName", SqlDbType.NVarChar,255),
					new SqlParameter("@FNewFileName", SqlDbType.NVarChar,255),
					new SqlParameter("@FExtName", SqlDbType.NVarChar,80),
					new SqlParameter("@FFileContent", SqlDbType.Image),
					new SqlParameter("@FLinkTypeCD", SqlDbType.NVarChar,6),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)};
            parameters[0].Value = model.FLinkTypeEntryID;
            parameters[1].Value = model.FLinkText;
            parameters[2].Value = model.FDispSeq;
            parameters[3].Value = model.FLinkURL;
            parameters[4].Value = model.FOldFileName;
            parameters[5].Value = model.FNewFileName;
            parameters[6].Value = model.FExtName;
            parameters[7].Value = model.FFileContent;
            parameters[8].Value = model.FLinkTypeCD;
            parameters[9].Value = model.FEntityNo;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-15</date>
        /// <param name="fLinkTypeEntryID">链接类型的编号（主键）</param>
        /// <returns>一个对象实体</returns>
        public Model.LinkTypeEntry GetModel(int fLinkTypeEntryID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FLinkText,FDispSeq,FLinkTypeEntryID,FLinkURL,FOldFileName,FNewFileName,FExtName,FFileContent,FLinkTypeCD,FEntityNo from t_LinkTypeEntry ");
            strSql.Append(" where FLinkTypeEntryID=@FLinkTypeEntryID ");
            SqlParameter[] parameters = {
					new SqlParameter("@FLinkTypeEntryID", SqlDbType.Int,4)};
            parameters[0].Value = fLinkTypeEntryID;

            Model.LinkTypeEntry model = new Model.LinkTypeEntry();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.FLinkText = ds.Tables[0].Rows[0]["FLinkText"].ToString();
                if (ds.Tables[0].Rows[0]["FDispSeq"].ToString() != "")
                {
                    model.FDispSeq = int.Parse(ds.Tables[0].Rows[0]["FDispSeq"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FLinkTypeEntryID"].ToString() != "")
                {
                    model.FLinkTypeEntryID = int.Parse(ds.Tables[0].Rows[0]["FLinkTypeEntryID"].ToString());
                }
                model.FLinkURL = ds.Tables[0].Rows[0]["FLinkURL"].ToString();
                model.FOldFileName = ds.Tables[0].Rows[0]["FOldFileName"].ToString();
                model.FNewFileName = ds.Tables[0].Rows[0]["FNewFileName"].ToString();
                model.FExtName = ds.Tables[0].Rows[0]["FExtName"].ToString();
                if (ds.Tables[0].Rows[0]["FFileContent"].ToString() != "")
                {
                    model.FFileContent = (byte[])ds.Tables[0].Rows[0]["FFileContent"];
                }
                model.FLinkTypeCD = ds.Tables[0].Rows[0]["FLinkTypeCD"].ToString();
                model.FEntityNo = ds.Tables[0].Rows[0]["FEntityNo"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-15</date>
        /// <param name="linkTypeArray">链接编号数组</param>
        /// <param name="entityNo">公司编号</param>

        public void DelMany(string[] linkTypeArray, string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            CommandInfo cmds = new CommandInfo();
            List<CommandInfo> cmdList = new List<CommandInfo>();

            if (linkTypeArray.Length > 0)
            {
                strSql = new StringBuilder();
                strSql.Append("delete from t_LinkTypeEntry ");
                strSql.Append(" where FLinkTypeEntryID=@FLinkTypeEntryID ");

                string strSqlAd = strSql.ToString();

                foreach (string linkTpyeEntry in linkTypeArray)
                {
                    cmds = new CommandInfo();

                    SqlParameter[] parameters = {
					    new SqlParameter("@FLinkTypeEntryID", SqlDbType.NVarChar,15)};

                    parameters[0].Value = linkTpyeEntry;

                    cmds.CommandText = strSqlAd;
                    cmds.Parameters = parameters;
                    cmdList.Add(cmds);
                }

            }

            DbHelperSQL.ExecuteSqlTranWithString(cmdList);

        }


        /// <summary>
        /// 删除一条数据
        /// </summary>
        /// <param name="fLinkTypeEntryID">链接类型的编号（主键）</param>
        public void DelLinkType(int fLinkTypeEntryID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from t_LinkTypeEntry ");
            strSql.Append(" where FLinkTypeEntryID=@FLinkTypeEntryID ");
            SqlParameter[] parameters = {
					new SqlParameter("@FLinkTypeEntryID", SqlDbType.Int,4)};
            parameters[0].Value = fLinkTypeEntryID;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 获得数据列表
        /// <creator>wangl</creator>
        /// <date>2013-09-09</date>
        /// </summary>
        public DataSet GetListByLinkType(string entityNo, string linkTypeCD)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FLinkTypeEntryID,FLinkText,FDispSeq,FLinkURL,FOldFileName,FNewFileName,FExtName,FFileContent,FLinkTypeCD,FEntityNo ");
            strSql.Append(" FROM t_LinkTypeEntry ");
            strSql.Append(" WHERE FLinkTypeCD=@FLinkTypeCD AND FEntityNo=@FEntityNo");
            strSql.Append(" ORDER BY FDispSeq");
            SqlParameter[] parameters = {
					new SqlParameter("@FLinkTypeCD", SqlDbType.NVarChar,6),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)};
            parameters[0].Value = linkTypeCD;
            parameters[1].Value = entityNo;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 得到一个对象实体
        /// <creator>wangl</creator>
        /// <date>2013-09-09</date>
        /// </summary>
        public Model.LinkTypeEntry DataRowToModel(DataRow row)
        {
            Model.LinkTypeEntry model = new Model.LinkTypeEntry();
            if (row != null)
            {
                if (row["FLinkTypeEntryID"] != null && row["FLinkTypeEntryID"].ToString() != "")
                {
                    model.FLinkTypeEntryID = int.Parse(row["FLinkTypeEntryID"].ToString());
                }
                if (row["FLinkText"] != null)
                {
                    model.FLinkText = row["FLinkText"].ToString();
                }
                if (row["FDispSeq"] != null && row["FDispSeq"].ToString() != "")
                {
                    model.FDispSeq = int.Parse(row["FDispSeq"].ToString());
                }
                if (row["FLinkURL"] != null)
                {
                    model.FLinkURL = row["FLinkURL"].ToString();
                }
                if (row["FOldFileName"] != null)
                {
                    model.FOldFileName = row["FOldFileName"].ToString();
                }
                if (row["FNewFileName"] != null)
                {
                    model.FNewFileName = row["FNewFileName"].ToString();
                }
                if (row["FExtName"] != null)
                {
                    model.FExtName = row["FExtName"].ToString();
                }
                if (row["FFileContent"] != null && row["FFileContent"].ToString() != "")
                {
                    model.FFileContent = (byte[])row["FFileContent"];
                }
                if (row["FLinkTypeCD"] != null)
                {
                    model.FLinkTypeCD = row["FLinkTypeCD"].ToString();
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
            }
            return model;
        }


    }
}
